Thumb

JavaScript Use Strict

1/21/2020 12:58:48 AM

In the JavaScript have strict keyword name as “use strict”. This is use for follow the rule and regulation of the JavaScript code. This keyword is very important role play in our code. Basically, if we don’t declare the variable in JavaScript then we can assign also we print the value. But when we use the “use strict” keyword above the JavaScript code then the JavaScript strictly follow the role of the programming. And our code didn’t   loosely code it become a strong type code. Now given bellow the “use strict” example code and explain the code:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript">
    //not declear just assgin also not use the "use strict" keyword .
   myValue=25;
   console.log("With out use use strict keyword: "+myValue);
</script>
<script type="text/javascript">
   // "use strict" code
  "use strict";
  var myValueTwo=25;
   console.log("use use strict keyword: "+myValueTwo);
 //not declear just assgin this code should not work.
 myValueThree=25;
 console.log("use use strict keyword: "+myValueThree);
</script>
</body>
</html>

In this code we see the how to work “use strict” keyword. Once we declare top the JavaScript code “use strict” keyword then we must and should follow the role and regulation otherwise it throws the exception or error in our code.